/**
 * Created by Administrator on 2018-08-10.
 *
 * 地面保障车辆管理
 */


define(function (require,exports,module) {
    var sTpl = require("./secVehicleControl.html");
    require("./secVehicleControl.css");
    require("../../../lib/fullcalendar/moment.min.js");

    var VueComponent = Vue.extend({
        template: sTpl,

        data:function () {
            var date = moment().format("YYYY-MM-DD");
            return {
                today:date,
                schedulings:[1,2,3,4,5,6],
                i:0,
                secpcData:[],
                flightInfo:{},
                jsLoaded:false,
                planes:[],
                form: {
                    flightInfo:{flightInfoId:""},
                },
            }
        },
        methods: {
            findFlightPlan:function () {
                var $this = this;
                axios.get(basepath+"/api/flightPlane/queryScheded?startDate="+this.today+"&scheduled=true"
                +"&endDate="+this.today+"&flightInfoId="+this.form.flightInfo.flightInfoId
                ).then(function (response) {

                    $this.secpcData=response.data;
                    $this.i=0;
                    var a= {};
                    $this.secpcData.forEach(function (val) {
                        val.schedulings.forEach(function (d) {

                            if(d.airSecurityVehiclePo&&d.airSecurityVehiclePo.vehicleType){
                                val[d.airSecurityVehiclePo.vehicleType] = d;
                                a[d.airSecurityVehiclePo.vehicleType]=d.airSecurityVehiclePo.vehicleType;
                            }
                        });
                    })
                    $this.schedulings=[];
                    for(var key in a){
                        $this.schedulings.push(key);
                    }

                });
            }
        },
        watch:{
            'jsLoaded':function (nv,ov) {
                if(nv){
                    loadMap();
                }
            }
        },
        computed:{

        },

        created:function () {
            var $this =this;
            require.async("https://webapi.amap.com/maps?v=1.3&key=8325164e247e15eea68b59e89200988b&plugin=ElasticMarker",function (data) {
                require.async("https://cache.amap.com/lbs/static/es5.min.js", function (data) {
                    $this.jsLoaded=true;
                });
            });
            this.findFlightPlan();
            var $this = this;
            axios.get(basepath+"/api/flightInfo/queryFlightInfo?filter=").then(function (response) {
                $this.planes=response.data;
                $this.planesMap={};
                $this.planes.forEach(function(plane){
                    plane.value= plane.flightNum;
                    $this.planesMap[plane.flightNum] = plane;
                })
            })

        },
        activated:function () {
            messages.$emit('change','车辆特种设备管理');
        }
    })
    module.exports=VueComponent;
    module.exports.reDefine=function (val) {
        module.exports.type=val;
        return module.exports;
    }

})
function loadMap() {
    var myMap;
    var infoWindow, map, level = 15,

        center = {lng:  102.932148, lat: 25.104922},
        features = [];

    map = new AMap.Map("mapContainer", {center: new AMap.LngLat(center.lng, center.lat), level: level,zoomEnable:false,
        dragEnable: false
    });

    new AMap.TileLayer.Satellite({map: map, zIndex: 1});

    // map.on('complete', function(){
    //     map.plugin(["AMap.ToolBar", "AMap.OverView", "AMap.Scale"], function(){
    //         map.addControl(new AMap.ToolBar);
    //         map.addControl(new AMap.OverView({isOpen: true}));
    //         map.addControl(new AMap.Scale);
    //     });
    //
    // })
    myMap =map;
    var template=$("#icon-template");
    function Marker(name,status,position){
        this.speed=300;
        this.marker =new AMap.Marker({autoRotation:true,map: myMap})
        this.content = template.children(0).clone();
        this.infoLabel=this.content.find(".info-label");
        this.consumeIcon=this.content.find(".consume-icon");
        this.nameLabel=this.content.find(".name-label");
        this.marker.setContent(this.content[0]);
        this.statusFlush =function(){
            this.infoLabel.removeClass("flash-label");
            this.infoLabel.addClass("flash-label");
        }
        this.setTransform =function(){
            this.consumeIcon.addClass("translate90")

        }
        this.setName = function (name) {
            this.nameLabel.html(name);
        }
        this.setStatus = function (status) {
            this.infoLabel.html(status);
        }
        this.setIcon=function (src) {
            this.consumeIcon.attr("src",src);
        }
        if(name){
            this.setName(name);
        }
        if(status){
            this.setStatus(status)
        }
        if(position){
            this.marker.setPosition(position);
        }
        var $this= this;
        var myMark = this;

        this.path = [];
        this.last = [];
        this.next = function () {
            var b;
            if($this.path.length>=1){
                b=$this.path.splice(0,1);
            }
            if(b[0].event){
                b[0].event()(function(){
                    $this.marker.moveTo(b[0], $this.speed);
                });
            }else{
                $this.marker.moveTo(b[0], $this.speed);
            }

        }
        this.remove =function () {
            myMap.remove(this.marker);
        }
        this.marker.on("moveend",function(o){
            if(myMark.path.length>=1){
                myMark.next();
            }
        });
        this.moveAlong = function (path) {
            var $this = this;
            var a= path.map(function (d,index) {
                return d;
            });
            this.path =a;
            if(this.path.length>=1);{
                this.last= this.path.splice(0,1);
                this.marker.moveTo(this.last[0], this.speed);
            }
        }
    }


    var guideCar = new Marker("引导车020","待出发");
    guideCar.marker.setAngle(180)
    guideCar.setIcon("/dam/icon/car.png");
    guideCar.setTransform();
    guideCar.marker.setPosition(new AMap.LngLat(102.938886,25.11602))

    var guideCarPath= [];
    // guideCarPath.push(new AMap.LngLat(102.938886,25.11602))
    guideCarPath.push(new AMap.LngLat(102.934508,25.111202))
    guideCarPath.push(new AMap.LngLat(102.932577,25.108715))
    guideCarPath.push(new AMap.LngLat(102.930732,25.106461))
    guideCarPath.push(new AMap.LngLat(102.930217,25.105839))
    guideCarPath.push(new AMap.LngLat(102.931547,25.105178))
    guideCarPath.push(new AMap.LngLat(102.931075,25.10444))

    guideCar.moveAlong(guideCarPath);


    var oilCar = new Marker("加油车","准备出发");

    oilCar.marker.setPosition(new AMap.LngLat(102.934208,25.095929));
    oilCar.setIcon("/dam/icon/car.png");
    oilCar.setTransform();
    var oilCarPath=[];
    oilCarPath. push(new AMap.LngLat(102.933092,25.096551))
    oilCarPath. push(new AMap.LngLat(102.932663,25.097678))
    oilCarPath. push(new AMap.LngLat(102.934122,25.097834))
    oilCarPath. push(new AMap.LngLat(102.935324,25.097523))
    oilCar.moveAlong(oilCarPath);



    myMap.on("click",function(po){console.log("push(new AMap.LngLat("+po.lnglat.lng+","+po.lnglat.lat+"))")})


}
//牵引车  行李传送车 行李牵引车 清水车 食品车 加油车 除冰车 摆渡车 客梯车 清水车 地面电源车 空调车

